package com.bysj.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.bysj.system.domain.CollectHouse;
import com.bysj.system.service.ICollectHouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房源收藏Controller
 * 
 * @author bysj
 * @date 2024-02-03
 */
@RestController
@RequestMapping("/system/collection")
public class CollectHouseController extends BaseController
{
    @Autowired
    private ICollectHouseService collectHouseService;

    /**
     * 查询房源收藏列表
     */
    @PreAuthorize("@ss.hasPermi('system:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(CollectHouse collectHouse)
    {
        startPage();
        List<CollectHouse> list = collectHouseService.selectCollectHouseList(collectHouse);
        return getDataTable(list);
    }

    /**
     * 导出房源收藏列表
     */
    @PreAuthorize("@ss.hasPermi('system:collection:export')")
    @Log(title = "房源收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CollectHouse collectHouse)
    {
        List<CollectHouse> list = collectHouseService.selectCollectHouseList(collectHouse);
        ExcelUtil<CollectHouse> util = new ExcelUtil<CollectHouse>(CollectHouse.class);
        util.exportExcel(response, list, "房源收藏数据");
    }

    /**
     * 获取房源收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:collection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(collectHouseService.selectCollectHouseById(id));
    }

    /**
     * 新增房源收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collection:add')")
    @Log(title = "房源收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollectHouse collectHouse)
    {
        return toAjax(collectHouseService.insertCollectHouse(collectHouse));
    }

    /**
     * 修改房源收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collection:edit')")
    @Log(title = "房源收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollectHouse collectHouse)
    {
        return toAjax(collectHouseService.updateCollectHouse(collectHouse));
    }

    /**
     * 删除房源收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collection:remove')")
    @Log(title = "房源收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(collectHouseService.deleteCollectHouseByIds(ids));
    }
}
